home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / gemfxm15.lzh / WND2XMPL.LZH / WND2XMPL.C < prev    next >
C/C++ Source or Header  |  1990-06-24  |  15KB  |  548 lines

  1. /* tab expansion/compression should be set to 4 in your editor */
  2. /**************************************************************************
  3.  *
  4.  * WINDXMPL.C - Demo of handling an object tree in a window, with some
  5.  *              emulation of form_do processing. 
  6.  *
  7.  *              This file demos many of the alternate AES bindings 
  8.  *              routines such as frmx_center and evnx_multi.
  9.  *************************************************************************/
  10.  
  11. #include <osbind.h>
  12. #include <gemfast.h> 
  13. #include "wnd2xmpl.h"
  14.  
  15. #define WI_KIND     (CLOSER+NAME)
  16. #define NO_WINDOW   -1
  17.  
  18. #define TRUE  1
  19. #define FALSE 0
  20.  
  21. extern int  thmo_redraw();
  22. extern int  thmo_attr();
  23. extern int  thmo_incr();
  24. extern int  thmo_start();
  25.  
  26. OBJECT  *menutree;
  27. OBJECT  *windtree;
  28.  
  29. GRECT   windrect;
  30.  
  31. int     wchar;
  32. int     hchar;
  33. int     wi_handle = NO_WINDOW;
  34. char    wi_name[] = " Window Demo 2 ";
  35.  
  36. extern int  gl_apid;
  37.  
  38. /**************************************************************************
  39.  *
  40.  * prg_init - Standard GEM startup.
  41.  *
  42.  *************************************************************************/
  43.  
  44. prg_init()
  45. {
  46.     int  dmy;
  47.     
  48.     appl_init();
  49.     
  50.     if (!rsrc_load("WND2XMPL.RSC")) {
  51.         form_alert(1,"[1][ | Can't load RSC! | ][ Fatal ]");
  52.         appl_exit();
  53.         Pterm(1);
  54.     }
  55.  
  56.     graf_handle(&wchar, &hchar, &dmy, &dmy);    /* For window min sizes */
  57.  
  58.     rsrc_gaddr(R_TREE, MENUTREE, &menutree);
  59.     rsrc_gaddr(R_TREE, WINDTREE, &windtree);
  60.  
  61.     *(char *)&windtree[WINDBXSP].ob_type |= 'S';     /* Stop     */
  62.     *(char *)&windtree[WINDBXGO].ob_type |= 'G';     /* Go       */
  63.     *(char *)&windtree[WINDBXPA].ob_type |= 'P';     /* Pause    */
  64.  
  65.     menu_bar(menutree, TRUE);
  66.  
  67.     graf_mouse(ARROW, 0L);    
  68. }
  69.  
  70. /**************************************************************************
  71.  *
  72.  * prg_exit - Standard GEM exit.
  73.  *
  74.  *************************************************************************/
  75.  
  76. prg_exit()
  77. {
  78.     w_close();
  79.     menu_bar(menutree, FALSE);
  80.     rsrc_free();
  81.     appl_exit();
  82.     Pterm(0);
  83. }
  84.  
  85. /**************************************************************************
  86.  *
  87.  * w_open - Create and open a window.
  88.  *  The display tree is centered, then the window is sized to hold it.
  89.  *
  90.  *************************************************************************/
  91.  
  92. w_open()
  93. {
  94.     GRECT   wrect;
  95.     GRECT   treerect;
  96.     GRECT   thmorect;
  97.     
  98.     if (wi_handle != NO_WINDOW) {       /* if window is already open,     */
  99.         return wi_handle;               /* just return the handle.        */
  100.     }
  101.  
  102.     frmx_center(windtree, &treerect);   /* center tree, sizes in treerect */
  103.  
  104.     winx_calc(WC_BORDER, WI_KIND, treerect, &wrect); /* calc window fullsize */
  105.  
  106.     wi_handle = wind_create(WI_KIND, wrect);         /* create window     */
  107.  
  108.     if (wi_handle < 0) {
  109.         form_error(4);                      /* can't open another window  */
  110.         wi_handle = NO_WINDOW;
  111.     } else {
  112.         wind_set(wi_handle, WF_NAME, wi_name, 0L);  /* set window title   */
  113.         wind_open(wi_handle, wrect);                /* open window        */
  114.     }
  115.     
  116.     winx_get(wi_handle, WF_WORKXYWH, &windrect);
  117.         
  118.     obj_offxywh(windtree, WINDPBTH, &thmorect);
  119.     thmo_attr(0,5);
  120.     thmo_start(100, &thmorect, FALSE);
  121.  
  122.     return wi_handle;
  123.  
  124. }
  125.  
  126. /**************************************************************************
  127.  *
  128.  * w_close - Close and delete a window.
  129.  *
  130.  *************************************************************************/
  131.  
  132. w_close()
  133. {
  134.     if (wi_handle != NO_WINDOW) {   /* only do close processing */
  135.         wind_close(wi_handle);      /* if the window is open!   */
  136.         wind_delete(wi_handle);
  137.         wi_handle = NO_WINDOW;
  138.     }
  139. }
  140.  
  141. /**************************************************************************
  142.  *
  143.  * do_redraw - Standard AES redraw handler for trees in windows.
  144.  *
  145.  *************************************************************************/
  146.  
  147. do_redraw(window, ptree, predrawrect)
  148.     register int      window;
  149.     register OBJECT   *ptree;
  150.     register GRECT    *predrawrect;
  151. {
  152.     register int      calltype;
  153.     register int      doneflag;
  154.     GRECT             t1;
  155.     GRECT             t2;
  156.  
  157. /*
  158.  * process the rectangle list for the window.  for each intersection of
  159.  * the area to be redrawn with a visible window rectangle, call objc_draw
  160.  * to draw that portion of the menu.
  161.  */
  162.  
  163.     wind_update(BEG_UPDATE);
  164.     
  165.     calltype = WF_FIRSTXYWH;
  166.     doneflag = FALSE;
  167.  
  168.     do  {
  169.         winx_get(window, calltype, &t1);
  170.         if (t1.g_w && t1.g_h) {
  171.             if (rc_intersect(predrawrect, &t1) && t1.g_w && t1.g_h) {
  172.                 objc_draw(ptree, R_TREE, MAX_DEPTH, t1);
  173.                 thmo_redraw(&t1);
  174.             }
  175.         } else {
  176.             doneflag = TRUE;
  177.         }
  178.         calltype = WF_NEXTXYWH;
  179.     } while (doneflag == FALSE);
  180.  
  181.     wind_update(END_UPDATE);
  182. }
  183.  
  184. /**************************************************************************
  185.  *
  186.  * hndl_message - Standard message handling code.
  187.  *
  188.  *************************************************************************/
  189.  
  190. hndl_message(msgbuf)
  191.     register int    *msgbuf;
  192. {
  193.     int             dmy;
  194.     int             top_window;
  195.     register OBJECT *ptree = windtree;
  196.     GRECT           t1, t2;
  197.  
  198.     switch (msgbuf[0]) {
  199.             
  200.     case MN_SELECTED:
  201.  
  202.         switch (msgbuf[4]) {
  203.         case MENUQUIT:
  204.             prg_exit();
  205.             break;
  206.         }
  207.         menu_tnormal(menutree, msgbuf[3], TRUE);
  208.         break;
  209.         
  210.     case WM_CLOSED:
  211.  
  212.         prg_exit();
  213.         break;
  214.  
  215.     case WM_TOPPED:
  216.     case WM_NEWTOP:
  217.  
  218.         wind_set(msgbuf[3], WF_TOP, 0L, 0L);
  219.         break;
  220.         
  221.     case WM_REDRAW:
  222.  
  223.         do_redraw(msgbuf[3], ptree, &msgbuf[4]);
  224.         break;
  225.  
  226.     case WM_MOVED:
  227.     case WM_SIZED:
  228.  
  229.         t1 = *(GRECT *)(&msgbuf[4]);
  230.         winx_calc(WC_WORK, WI_KIND, t1, &t2);
  231.  
  232.         ptree->ob_x = t2.g_x;
  233.         ptree->ob_y = t2.g_y;
  234.  
  235.         rc_intersect(&ptree->ob_x, &t2);
  236.         if (t2.g_w < wchar)
  237.             t2.g_w = wchar;
  238.         if (t2.g_h < hchar)
  239.             t2.g_h = hchar;
  240.  
  241.         winx_calc(WC_BORDER, WI_KIND, t2, &t1);
  242.         wind_set(msgbuf[3], WF_CURRXYWH, t1);
  243.  
  244.         break;
  245.                 
  246.     } /* END switch (msgbuf[0]) */
  247.  
  248. }
  249.  
  250.  
  251. /**************************************************************************
  252.  *
  253.  * rbselect - Visually select indicated radio button, de-sel old button.
  254.  *
  255.  *************************************************************************/
  256.  
  257. rbselect(ptree, selobj)
  258.     register OBJECT *ptree;
  259.     register int    selobj;
  260. {
  261.     register int    oldobj;
  262.  
  263.     oldobj = obj_rbselect(ptree, selobj, SELECTED);
  264.     objc_draw(ptree, selobj, MAX_DEPTH, windrect);
  265.     if (oldobj > R_TREE && oldobj != selobj) {
  266.         objc_draw(ptree, oldobj, MAX_DEPTH, windrect);
  267.     }
  268. }
  269.  
  270. /**************************************************************************
  271.  *
  272.  * hndl_button - Handle a button click in our window.
  273.  *
  274.  *  This routine handles radio button clicks, and clicks on SELECTABLE
  275.  *  objects that are not DISABLED.  It basically mimics the actions of
  276.  *  the form_do() click handler...radio button clicks are processed
  277.  *  immediately, then the mouse is ignored until the button is released.
  278.  *  Clicks on non-radio objects will track the mouse, and will handle
  279.  *  the object based on where the mouse is when the button is released.
  280.  *
  281.  *************************************************************************/
  282.  
  283. hndl_button(mx, my, mb)
  284.     int mx, my, mb;
  285. {
  286.     int             dmy;
  287.     register int    oldobj;
  288.     register int    selobj;
  289.     register int    in_obj;
  290.     register OBJECT *ptree = windtree;
  291.     register OBJECT *pobj;
  292.     
  293.     selobj = objc_find(ptree, R_TREE, MAX_DEPTH, mx, my);
  294.     pobj   = &ptree[selobj];
  295.     
  296.     if (selobj <= R_TREE || (pobj->ob_state & DISABLED) ) {
  297.         return NO_OBJECT;
  298.     }
  299.  
  300.     wind_update(BEG